<?php
class login extends control
{
	private $user;
	
	public function __construct() {
		parent::__construct();
		$this->user = $this->loadModel('user');
	}
	
	public function login() {
		$user_name = $this->load->input->string('user_name');
		$user_pass = $this->load->input->string('user_pass');
		
		$user_pass=md5($user_pass);

		$cond = array('user_name'=>$user_name,'user_pass'=>$user_pass);
		$field = array('user_id','user_name');
		$row = $this->user->find($cond,$field);
		
		if($row) {
			//var_dump($result);
			//注册会话变量
			$this->load->session->set('user_id',$row['user_id']);
			$this->load->session->set('user_name',$row['user_name']);
			
			$data = array('success'=>true,'msg'=>'ok');
		} else {
			$data = array('success'=>true,'msg'=>'用户名和密码错误请重试');
		}
		echo json_encode($data);
	}
	
	public function register() {
		$user_name = $this->load->input->string('user_name');
		$user_pass = $this->load->input->string('user_pass');
		$user_passconf = $this->load->input->string('user_passconf');
		$user_pass = $this->load->input->email('user_email');
		
		//$validate_password = $this->load->input->validPass($user_pass,$user_passconf);
		
		if($user_pass == $user_passconf) {
			$cond = array('user_name'=>$user_name);
			$check_user_name = $this->user->find($cond);
			
			if($check_user_name) {
				
			} else {
				$data = array('success'=>true,'msg'=>'用户名已经被占用，请更换');
			}
			
		} else {
			$data = array('success'=>true,'msg'=>'两次输入的密码不一致');
		}
		echo json_encode($data);
	}
	
	/**
	  *注销系统登录用户
	  * 
	 **/
	public function logout() {
		$this->load->session->logout();
	}
}
?>
